home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Human Interface Toolbox / Tabs LDEF / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.3 KB  |  185 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Events.c
  3.  
  4.     Contains:    Main event loop and basic keyboard/mouse processing
  5.  
  6.     Written by: Chris White    
  7.  
  8.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/10/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24.  
  25. #pragma segment Core
  26.  
  27.  
  28. // System Includes
  29.  
  30. #ifndef __MEMORY__
  31.     #include <Memory.h>
  32. #endif
  33.  
  34. #ifndef __APPLEEVENTS__
  35.     #include <AppleEvents.h>
  36. #endif
  37.  
  38. #ifndef __DIALOGS__
  39.     #include <Dialogs.h>
  40. #endif
  41.  
  42. #ifndef __DESK__
  43.     #include <Desk.h>
  44. #endif
  45.  
  46. #ifndef __WINDOWS__
  47.     #include <Windows.h>
  48. #endif
  49.  
  50.  
  51.  
  52.  
  53. // Application includes
  54.  
  55. #ifndef __BAREBONES__
  56.     #include "BareBones.h"
  57. #endif
  58.  
  59. #ifndef __PROTOTYPES__
  60.     #include "Prototypes.h"
  61. #endif
  62.  
  63.  
  64.  
  65.  
  66. // static includes
  67.  
  68. static void DoMouseDown ( EventRecord* theEvent );
  69. static void DoKey ( EventRecord*theEvent );
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. void EventLoop ( void )
  77. {
  78.     OSErr            theErr;
  79.     EventRecord        theEvent;
  80.     
  81.     
  82.     while ( !gQuit )
  83.     {
  84.         WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );    
  85.         
  86.         switch ( theEvent.what )
  87.         {
  88.             case mouseDown: 
  89.                 DoMouseDown ( &theEvent );
  90.             break;
  91.             
  92.             case keyDown:
  93.             case autoKey: 
  94.                 DoKey ( &theEvent );
  95.             break;
  96.             
  97.             case activateEvt: 
  98.                 DoActivate ( &theEvent );
  99.             break;
  100.             
  101.             case updateEvt:
  102.                 DoUpdate ( &theEvent );
  103.             break;
  104.             
  105.             case osEvt:
  106.                 if ( (theEvent.message >> 24) & suspendResumeMessage )    // suspend or resume
  107.                 {
  108.                     // Modify the event record to look like an activate/deactivate event
  109.                     theEvent.modifiers = theEvent.message;        // Copy suspend/resume flag
  110.                     theEvent.message = (long) FrontWindow ( );    
  111.                     DoActivate ( &theEvent );
  112.                 }
  113.             break;
  114.             
  115.             case kHighLevelEvent:
  116.                 theErr = AEProcessAppleEvent ( &theEvent );
  117.             break;
  118.         }
  119.     }
  120.     
  121.     return;
  122.     
  123. } // EventLoop
  124.  
  125.  
  126.  
  127. static void DoMouseDown ( EventRecord* theEvent )
  128. {
  129.     Point            globalPt = theEvent->where;
  130.     SInt16            windowPart;
  131.     WindowRef        theWindow;
  132.     long            theMenu;
  133.     
  134.     
  135.     windowPart = FindWindow ( globalPt, &theWindow );
  136.     switch ( windowPart )
  137.     {
  138.         case inMenuBar: 
  139.             theMenu = MenuSelect ( globalPt );
  140.             MenuDispatch ( theMenu );
  141.         break;
  142.         
  143.         case inSysWindow:
  144.             // The SystemClick toolbox routine handles system events
  145.             SystemClick ( theEvent, theWindow );
  146.         break;
  147.         
  148.         case inGoAway:
  149.             // We'll quit when the user closes the window
  150.             if ( TrackGoAway ( theWindow, theEvent->where ) )
  151.                 gQuit = true;
  152.         break;
  153.         
  154.         case inDrag:
  155.             DoDragWindow ( theWindow, theEvent );
  156.         break;
  157.  
  158.         case inContent:
  159.             DoContentClick ( theWindow, theEvent );
  160.         break;
  161.     }
  162.     
  163.     return;
  164.     
  165. } // DoMouseDown
  166.  
  167.  
  168.  
  169. static void DoKey ( EventRecord* theEvent )
  170. {
  171.     char keyPressed = (theEvent->message & charCodeMask);
  172.     
  173.     
  174.     // Command keys get handled by the menu handling routines
  175.     if ( theEvent->modifiers & cmdKey )
  176.         MenuDispatch ( MenuKey ( keyPressed ) );
  177.     
  178.     return;
  179.     
  180. } // DoKey
  181.  
  182.  
  183.  
  184.  
  185.